﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.

using DWF.Studio.ScriptEngine.Event;
using System;
using System.Activities.Tracking;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.ScriptEngine.Custom
{
    internal class WorkflowTrackingParticipant : TrackingParticipant
    {
        private Action<ExecuteTrackEventArgs> _excuteTrack;

        public WorkflowTrackingParticipant(Action<ExecuteTrackEventArgs> excuteTrack)
        {
            _excuteTrack = excuteTrack;
        }

        protected override void Track(TrackingRecord trackRecord, TimeSpan timeStamp)
        {
            ActivityStateRecord recordEntry = trackRecord as ActivityStateRecord;

            if (recordEntry != null)
            {
                this._excuteTrack?.Invoke(new ExecuteTrackEventArgs($"[{recordEntry.EventTime.ToLocalTime().ToLongTimeString()}] [{recordEntry.Activity.Id}] [{recordEntry.Activity.Name}]  [{recordEntry.State}]"));
            }
        }
    }
}
